<?php echo($javascript->link("countdown.js"));  ?>

<div class="sales view">
	<ul class="viewitems">

	<li>
	<dl>
		<dt><?php __('Item'); ?></dt>
		<dd>
			<?php echo $html->link($sale['Item']['name'], array('controller' => 'items', 'action' => 'view', $sale['Item']['id'])); ?>
			&nbsp;
		</dd>
		<dt><?php __('Time End'); ?></dt>
		<dd >
					<label id = '<?php echo '0'; ?>'> </label>
					<?php 
						$year = date("Y",strtotime($sale['Sale']['timeEnd'])); 
						$month = date("m",strtotime($sale['Sale']['timeEnd']));
						$day = date("d",strtotime($sale['Sale']['timeEnd']));
						$hour = date("H",strtotime($sale['Sale']['timeEnd']));
						$minutes = date("i",strtotime($sale['Sale']['timeEnd']));
						$seconds = date("s",strtotime($sale['Sale']['timeEnd']));
						$timeLeft = '<script> countdown('.$year.','. $month.','. $day.','. $hour.','. $minutes.','. $seconds.',"0")</script>';
					
						if($sale['Sale']['timeEnd'] <= date('Y-m-d H:i:s'))
						{
							echo __('Lasted: ').$timediff->timeDiff($sale['Sale']['originalTimeEnd'],$sale['Sale']['timeEnd']);	
						} else
						{
							echo $timeLeft;
						}
					
					?>
					
					
		</dd>
		<dt><?php __('Price'); ?></dt>
		<dd>
			<?php 
				echo number_format($sale['Sale']['currentPrice']*$currencyValue,2); 
				echo ' '; 
				echo $currencyName;
				
				if($sale['Sale']['timeEnd'] < date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']))
				{
					echo '<br>';
					echo __('Usou ').$nLicitations;
					echo __(' lances<br>Preço total: ').number_format($totalPrice*$currencyValue,2); 
					echo ' '; 
					echo $currencyName;
				}
			?>
			&nbsp;
		</dd>
		<dt><?php __('Last bid'); ?></dt>
		<dd>
			<?php echo $html->link($sale['User']['login'], array('controller' => 'users', 'action' => 'view', $sale['User']['id'])); ?>
			&nbsp;
		</dd>
		
		<dt><?php __('Last 10 bids'); ?></dt>
		<dd>
			<?php
				
				foreach($licitations as $licitation):
					echo(date('H:i', strtotime($licitation['Licitation']['timeLicitation']))).' ';
					echo number_format($licitation['Licitation']['price']*$currencyValue,2); 
					echo ' '; 
					echo $currencyName.' ';
					echo($licitation['User']['login']).'<br>';	
				endforeach;
			
			?>
			&nbsp;
		</dd>
		
	
		<dt>&nbsp;</dt>
		<dd>
			<?php 
				if($sale['Sale']['timeEnd'] > date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']))
				{ 
					echo $html->link(__('Licitate', true), array('action' => 'licitate', $sale['Sale']['id'],'view',$sale['Sale']['id'])); 
					
					if(!$isFollowing)
						echo $html->link(__('Follow', true), array('action' => 'follow', $sale['Sale']['id'])); 
					else	
						echo $html->link(__('Unfollow', true), array('action' => 'unfollow', $sale['Sale']['id']));
				}
				echo $html->link(__('Buy Now', true), array('action' => 'buyNow', $sale['Sale']['id'],'buy',$sale['Sale']['id'])); ?>
			&nbsp;
		</dd>	
	</dl>
	</li>
			<li>
			<?php 	
								$photo = $sale['Item']['Photo'][0] ;
								echo $html->link($html->image('photos/home/'.$photo['urlPhoto'], array('width' => 100, 'height' => 150)),
												array('controller' => 'sales', 'action' => 'view', $sale['Sale']['id']),
												array('escape' => false));
			?>
		</li>
		<?php if($sale['Sale']['timeEnd'] > date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])) {  ?>
		<li>
			<dl>
			<dt>
				<?php echo __('Bid Agent'); ?>
			</dt>
					<?php 
					//verificar se venda inda está 'aberta'
					if(!$hasAgent)
					{
						echo $form->create(array('url'=>array('controller'=>'Bidagents','action'=>'add', $sale['Sale']['id'])));
					  	echo $form->input('licitationsLeft'); 
					  	echo $form->end('Submit'); 
					} else
					{
						echo('Licitations left: '.$agent['Bidagent']['licitationsLeft']).'<br>';
					}
					?> 
			</dl>
		</li>
		<?php } ?>
		<li>
			<dl>
			<dt>
				<?php echo __('Item description'); ?>
			</dt>
				<dd> <?php echo $sale['Item']['description']; ?></dd>
			</dl>
		</li>
	</ul>
	
</div>
